import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/common/function_id.dart';
import 'package:ty_smart_watch/common/images_url.dart';
import 'package:ty_smart_watch/page/health/controller/common_controller.dart';
import 'package:ty_smart_watch/utils/Log.dart';

class MaxMinComponent extends StatelessWidget {
  const MaxMinComponent({super.key, required this.functionId});

  final int functionId;

  @override
  Widget build(BuildContext context) {
    final CommonController controller = Get.find();
    Log.d("function id : $functionId");
    return Row(
      children: [
        Expanded(
          child: Item(
            img: _getIcon(functionId)[0],
            title: _getTitle(functionId, 0),
            data: controller.currentData.value.toString(),
          ),
        ),
        Expanded(
          child: Item(
            img: _getIcon(functionId)[1],
            title: _getTitle(functionId, 1),
            data: controller.maxData.value.toString(),
          ),
        ),
        Expanded(
          child: Item(
            img: _getIcon(functionId)[2],
            title: _getTitle(functionId, 2),
            data: controller.minData.value.toString(),
          ),
        ),
      ],
    );
  }

  List<String> _getIcon(int id) {
    List<String> iconList = <String>[];
    switch (id) {
      case HEART:
        iconList = [HEART_CURRENT, HEART_HIGH, HEART_LOW];
        break;
      case BLOOD_OXYGEN:
        iconList = [BLOOD_OXYGEN_CURRENT, BLOOD_OXYGEN_HIGH, BLOOD_OXYGEN_LOW];
        break;
      case BLOOD_PRESSURE:
        iconList = [BLOOD_PRESSURE_CURRENT, BLOOD_PRESSURE_HIGH, BLOOD_PRESSURE_LOW];
        break;
      case BLOOD_GLUCOSE:
        iconList = [BLOOD_GLUCOSE_CURRENT, BLOOD_GLUCOSE_HIGH, BLOOD_GLUCOSE_LOW];
        break;
      case BODY_TEMPERATURE:
        iconList = [BODY_TEMPERATURE_CURRENT, BODY_TEMPERATURE_HIGH, BODY_TEMPERATURE_LOW];
        break;
      default:
        iconList = ["", "", ""];
    }
    return iconList;
  }

  String _getTitle(int id, int index) {
    if (index == 0) {
      return "最近一次";
    }
    String title = "";
    String state = "";
    switch (id) {
      case HEART:
        title = "心率";
      case BLOOD_OXYGEN:
        title = "血氧";
      case BLOOD_GLUCOSE:
        title = "血糖";
      case BODY_TEMPERATURE:
        title = "体温";
      case BLOOD_PRESSURE:
        title = "血压";
    }
    switch (index) {
      case 0:
        state = "最近一次";
      case 1:
        state = "最高";
      case 2:
        state = "最低";
    }
    return state + title;
  }
}

class Item extends StatelessWidget {
  final String data;
  final String title;
  final String img;

  const Item({super.key, required this.data, required this.title, required this.img});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 6),
      padding: EdgeInsets.symmetric(vertical: 16, horizontal: 10),
      decoration: BoxDecoration(
        //圆角半径
        borderRadius: const BorderRadius.all(Radius.circular(12.0)),
        //边框线宽、颜色
        border: Border.all(width: 1.0, color: const Color(0xFF6D6D6D)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Image.asset(img, width: 20, height: 20),
          Text(
            data,
            style: TextStyle(fontSize: 18),
          ),
          Text(
            title,
            style: TextStyle(color: Color(0xFF898996), fontSize: 10),
          )
        ],
      ),
    );
  }
}
